package com.atguigu.gmall.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * @author atguigu-mqx
 */
@Configuration
public class DelayedMqConfig {

    //  延迟队列---插件实现： 需要一套交换机队列绑定关系！
    public static final String exchange_delay = "exchange.delay";
    public static final String routing_delay = "routing.delay";
    public static final String queue_delay_1 = "queue.delay.1";

    @Bean
    public CustomExchange delayExchange(){
        //  声明一个map 集合
        HashMap<String, Object> map = new HashMap<>();
        map.put("x-delayed-type","direct");
        return new CustomExchange(exchange_delay,"x-delayed-message",true,false,map);
    }

    @Bean
    public Queue delayQueue(){
        //  声明队列
        return new Queue(queue_delay_1,true,false,false);
    }

    @Bean
    public Binding delayBinding(){
        //  设置绑定关系！
        return BindingBuilder.bind(delayQueue()).to(delayExchange()).with(routing_delay).noargs();
    }
}
